package com.netty.pro.netty.inbound_outbound;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author xuzn
 * @ClassName: MyByteToLongEncoder
 * @ProjectName netty-pro
 * @date 2020/3/20/9:23
 */
public class MyLongToByteEncoder extends MessageToByteEncoder<Long> {
  /**
   * MessageToByteEncoder<Long>
   * 此处的类型要和传入的类型匹配,否则就会跳过encoder
   */
  @Override
  protected void encode(ChannelHandlerContext ctx, Long msg, ByteBuf out) throws Exception {
    System.out.println("MyLongToByteEncoder 的encoder方法被调用");
    out.writeLong(msg);
  }
}
